\documentclass{scrreprt}

%Imports

\newcommand{\company}{cool-aid.nl}
\newcommand{\product}{Tic-Tac-Toe-Server}

\newcommand{\tane}{Tane van Wifferen}
\newcommand{\martijn}{Martijn Verbakel}

\title{TEMPLATE FOR SPECIFICATIONS FOR COOL-AID.NL}
\author{Martijn Verbakel, Tane van Wifferen}
\begin{document}
\maketitle
\tableofcontents
\newpage
\chapter{Introduction}
\section{Changelog}
\begin{center}
	\begin{tabular}{| l | l | l | r |}
		\hline
		Name & Date & Version & Comment\\
		\hline
		Tane & March 30, 2014 & 0.1 & Initial Release\\
		\hline
	\end{tabular}
\end{center}

\newpage
\section{Introduction to the product}
This document will show a design specification for the internals of the \product. I made this document, so doing the programming will be easier to do later. If the internals change, please change this document too. 

\chapter{General Setup}
\section{intro}
When the program is first launched, a simple CLI is presented, this is the User Interface. It has possibilities to add or remove options, these are classes that extend the Command-interface. When using the server you usually want a startServer class, which uses the Server class. Using these tools you will be able to run a server-client set up which handles multiple connections on it's own, and you will only need to edit the GameServerThread.java file to implement game functionality. I will go into some detail about the classes in the coming chapters.

\chapter{Design}
\section{Class Design}
The classes that are used are:

\begin{itemize}
	\item TicTacToeServer
	\item ServerStatus
	\item UserInterface
	\item Server
	\item GameServerThread
\end{itemize}

\noindent Interfaces that are used are:
\begin{enumerate}
	\item Command
\end{enumerate}

\noindent Extentions of these interfaces are:
\begin{enumerate}
	\item Command:
	       	\begin{itemize}
			\item ToggleServer
			\item Exit
		\end{itemize}
\end{enumerate}

\section{TicTacToeServer}
This is the class that is started when you want to execute the program. It only holds the main thread, which handles the parameters that are supplied, and then starts a new UserInterface.

\section{ServerStatus}
An object that handles communication between the UserInterface and the Server classes. This is synchronized between threads, and checked every five seconds (The socket timeout (hardcoded)). 
\\
public fields:
\begin{itemize}
	\item running : boolean (initialised as false)
\end{itemize}

\section{UserInterface}
This is the class that handles all the things shown on screen. It is a numbered menu, with the possibility to add and remove functions. These can be anything, the only requirement is that any function that is added is a Command.
\\
fields:
\begin{itemize}
	\item serverRunning : boolean (initialised as false) \\ Indicates wether the server is started yet. Public, and should be changed directly.
	\item commands : ArrayList<Command> \\ An arraylist with all the commands that can be executed.
	\item commandStrings: ArrayList<String> \\ And arraylist with all the strings that will be printed on screen. This is closely related to 'commands', and will always resemble the commands in 'commands'.
	\item port: int \\ the port the serverSocket will listen to.
\end{itemize}

Constructor:\\
The standard constructor looks like this:\\
public UserInterface(int portnumber);\\

Public Methods:
\begin{itemize}
	\item showMenu() : void \\ Clears the screen, and prints a line for every string in commandStrings.
	\item appendOption(String name, Command command) : void \\ Adds a specific command with a specific name to the list. 
	\item removeOption(int index) : void \\ removes the specific item from commandStrings as well as from Commands.
\end{itemize}

\section{Server implements Runnable}
A class that handles all the connection logic. It gives each incoming connection its own thread, for multiple connection possibilities. Communication with the server goes through the ServerStatus object. This will be altered through a Command, in this case the ToggleServer Command.

Fields:
\begin{itemize}
	\item serverStatus : ServerStatus \\ The synchronized object containing the state the server should be in.
	\item connectionPort : int \\ The port that the ServerSocket initialises on.
	\item serverRunning : boolean \\ The state the server is in at the moment. When serverStatus.running is checked, it is compared to serverRunning. The Server will only alter serverRunning. 
\end{itemize}
\end{document}
